package com.sskj.lib.util;


import com.sskj.common.util.NumberUtil;

public class CoinUtil {
    public static String showName(String code) {
        return code.replace("_", "/").toUpperCase();
    }

    public static String keepRMB(String rmb) {
        return NumberUtil.keep2(rmb);
    }

    public static String keepRMB(double rmb) {
        return keepRMB(rmb + "");
    }

    //代币
    public static String keepCoin(String coin) {
        return NumberUtil.keep(coin, 6);
    }

    public static String keepCoin(double coin) {
        return keepCoin(coin + "");
    }

    public static String keepUSDT(String coin) {
        return NumberUtil.keepMax(coin, 4);
    }

    public static String keepUSDT(double coin) {
        return keepUSDT(coin + "");
    }

    /**
     * 币种价格
     * @param code
     * @param price
     * @return
     */
    public static String keepCoinPriceMax(String code, String price) {
        code = code.replace("_", "/").toUpperCase();
        switch (code) {
            case "BTC/USDT":
            case "ETH/USDT":
            case "LTC/USDT":
            case "BCH/USDT":
                return NumberUtil.keepMax2(price);
            case "FEC/MYR":
            case "FEC/USDT":
                return NumberUtil.keepMax(price,3);
            case "OMG/USDT":
            case "GNT/USDT":
            case "EOS/USDT":
            case "PST/USDT":
            case "XRP/USDT":
            case "ETC/USDT":
            case "ZRX/USDT":
            case "MANA/USDT":
            case "CQTF/USDT":
                return NumberUtil.keepMax4(price);
            case "OMG/BTC":
            case "OMG/ETH":
            case "PST/ETH":
            case "ETH/BTC":
            case "LTC/BTC":
            case "ETC/BTC":
            case "BCH/BTC":
            case "XMR/ETH":
            case "TRX/ETH":
                return NumberUtil.keepMax(price, 6);
            case "ZRX/BTC":
            case "BAT/BTC":
            case "GNT/BTC":
            case "PST/BTC":
            case "MANA/BTC":
            case "EOS/BTC":
            case "XRP/BTC":
            case "EOS/ETH":
                return NumberUtil.keepMax(price, 8);
            case "ZRX/ETH":
            case "BAT/ETH":
            case "GNT/ETH":
            case "MANA/ETH":
                return NumberUtil.keepMax4(price);
            default:
                return NumberUtil.keepMax4(price);

        }
    }
    /**
     * 币种价格
     * @param code
     * @param price
     * @return
     */
    public static String keepCoinPrice(String code, String price) {
        try {
            Double.valueOf(price);
        }catch (Exception e){
            return price;
        }
        code = code.replace("_", "/").toUpperCase();
        switch (code) {
            case "BTC/USDT":
            case "ETH/USDT":
            case "BCH/USDT":
            case "LTC/USDT":
            case "DASH/USDT":
                return NumberUtil.keep2(price);
            case "ETC/USDT":
            case "EOS/USDT":
            case "HT/USDT":
            case "IMC/USDT":
                return NumberUtil.keep4(price);
            case "XRP/USDT":
            case "TRX/USDT":
                return NumberUtil.keep(price,5);
            default:
                return NumberUtil.keep4(price);

        }
    }


    /**
     * 获取币种价格保留位数
     * @param code
     * @return
     */
    public static int getPriceKeepNum(String code) {
        code = code.replace("_", "/").toUpperCase();
        switch (code) {
            case "BTC/USDT":
            case "ETH/USDT":
            case "BCH/USDT":
            case "LTC/USDT":
            case "DASH/USDT":
                return 2;
            case "ETC/USDT":
            case "EOS/USDT":
            case "HT/USDT":
            case "IMC/USDT":
                return 4;
            case "XRP/USDT":
            case "TRX/USDT":
                return 5;
            default:
                return 2;
        }
    }

    /**
     * 获取币种数量保留位数
     * @param code
     * @return
     */
    public static int getNumKeepNum(String code) {
        code = code.replace("_", "/").toUpperCase().split("/")[0];
        switch (code) {
            case "USDT":
            case "BTC":
            case "OMG":
            case "GNT":
            case "ETH":
                return 4;
            case "PST":
            case "ZRX":
            case "MANA":
            case "CQTF":
                return 2;
            default:
                return 4;
        }
    }

    public static int coinGrade(String code) {
        code = code.replace("_", "/").toUpperCase();
        switch (code) {
            case "BTC/USDT":
            case "ETH/USDT":
                return 2;
            case "OMG/USDT":
            case "GNT/USDT":
            case "PST/USDT":
            case "ZRX/USDT":
            case "MANA/USDT":
            case "CQTF/USDT":
            case "ZRX/ETH":
            case "BAT/ETH":
            case "GNT/ETH":
            case "MANA/ETH":
                return 4;
            case "OMG/BTC":
            case "OMG/ETH":
            case "PST/ETH":
                return 6;
            case "ZRX/BTC":
            case "BAT/BTC":
            case "GNT/BTC":
            case "PST/BTC":
            case "MANA/BTC":
                return 8;
            default:
                return 4;

        }
    }

    public static String keepCoinNumMax(String code, Double num) {
        return keepCoinNumMax(code, num + "");
    }

    public static String keepCoinNumMax(String code, String num) {
        code = code.replace("_", "/").toUpperCase().split("/")[0];
        switch (code) {
            case "USDT":
            case "BTC":
            case "OMG":
            case "GNT":
            case "ETH":
                return NumberUtil.keepMax4(num);
            case "PST":
            case "ZRX":
            case "MANA":
            case "CQTF":
                return NumberUtil.keepMax2(num);
            default:
                return NumberUtil.keepMax4(num);
        }
    }

    public static String keepAsset(String code, String num) {
        code = code.replace("_", "/").toUpperCase();
        switch (code) {
            case "USDT":
                return NumberUtil.keepMax4(num);
            default:
                return NumberUtil.keepMax(num, 8);
        }
    }
}
